﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HyperPin_Database_Editor
{
    public partial class HPVideoSettings : HPSettingsPanel
    {
        //static string iniSection = "Video";
        static string iniPlayfieldMonitor = "Playfield_Monitor";
        static string iniPlayfieldRotation = "Playfield_Rotation";
        static string iniQuality = "Quality";
        static string iniTableVideoEnabled = "Table_Video_Enabled";
        static string iniTableVideoOffset = "Table_Video_Offset";
        static string iniUseBackglass = "Use_Backglass";
        static string iniBackglassMonitor = "Backglass_Monitor";
        static string iniBackglassImageX = "Backglass_Image_x";
        static string iniBackglassImageY = "Backglass_Image_y";
        static string iniBackglassImageW = "Backglass_Image_w";
        static string iniBackglassImageH = "Backglass_Image_h";
        static string iniBackglassImageR = "Backglass_Image_r";
        static string iniBackglassDelay = "Backglass_Delay";

        public HPVideoSettings()
        {
            //currentSettingsSection = "Video";
            InitializeComponent();
        }

        public override void doLoadSettings()
        {
            comboPlayfieldMonitor.Text = readSetting(iniPlayfieldMonitor, "Primary");
            comboPlayfieldRotation.Text = readSetting(iniPlayfieldRotation, "0");
            comboQuality.Text =readSetting(iniQuality, "0");
            checkTableVideos.Checked = readSettingBool(iniTableVideoEnabled, false);
            numericTableVideoOffset.Value = readSettingInt(iniTableVideoOffset, 0);
            checkBackglassEnabled.Checked = readSettingBool(iniUseBackglass, false);
            comboBackglassMonitor.Text = readSetting(iniBackglassMonitor, "Primary");
            numericBackglassX.Value = readSettingInt(iniBackglassImageX, 0);
            numericBackglassY.Value = readSettingInt(iniBackglassImageY, 0);
            numericBackglassW.Value = readSettingInt(iniBackglassImageW, 0);
            numericBackglassH.Value = readSettingInt(iniBackglassImageH, 0);
            comboBackglassR.Text =readSetting(iniBackglassImageR, "0");
            numericBackglassDelay.Value = readSettingDecimal(iniBackglassDelay, (decimal)0.1);

            updateOptionalControls();
        }

        protected void updateOptionalControls()
        {
            numericTableVideoOffset.Enabled = checkTableVideos.Checked;
            labelTableVideoOffset.Enabled = checkTableVideos.Checked;

            labelBackglassMonitor.Enabled = checkBackglassEnabled.Checked;
            comboBackglassMonitor.Enabled = checkBackglassEnabled.Checked;
            labelBackglassOffset.Enabled = checkBackglassEnabled.Checked;
            numericBackglassX.Enabled = checkBackglassEnabled.Checked;
            numericBackglassY.Enabled = checkBackglassEnabled.Checked;
            labelBackglassOffset.Enabled = checkBackglassEnabled.Checked;
            numericBackglassW.Enabled = checkBackglassEnabled.Checked;
            numericBackglassH.Enabled = checkBackglassEnabled.Checked;
            labelBackglassRotation.Enabled = checkBackglassEnabled.Checked;
            comboBackglassR.Enabled = checkBackglassEnabled.Checked;
            labelBackglassDelay.Enabled = checkBackglassEnabled.Checked;
            numericBackglassDelay.Enabled = checkBackglassEnabled.Checked;
        }

        public override void doSaveSettings()
        {
            writeSetting(iniPlayfieldMonitor, comboPlayfieldMonitor.Text);
            writeSetting(iniPlayfieldRotation, comboPlayfieldRotation.Text);
            writeSetting(iniQuality, comboQuality.Text);
            writeSettingBool(iniTableVideoEnabled, checkTableVideos.Checked);
            writeSettingInt(iniTableVideoOffset, Convert.ToInt32(numericTableVideoOffset.Value));
            writeSettingBool(iniUseBackglass, checkBackglassEnabled.Checked);
            writeSetting(iniBackglassMonitor, comboBackglassMonitor.Text);
            writeSettingInt(iniBackglassImageX, Convert.ToInt32(numericBackglassX.Value));
            writeSettingInt(iniBackglassImageY, Convert.ToInt32(numericBackglassY.Value));
            writeSettingInt(iniBackglassImageW, Convert.ToInt32(numericBackglassW.Value));
            writeSettingInt(iniBackglassImageH, Convert.ToInt32(numericBackglassH.Value));
            writeSetting(iniBackglassImageR, comboBackglassR.Text);
            writeSettingDecimal(iniBackglassDelay, numericBackglassDelay.Value);
        }

        private void checkTableVideos_CheckedChanged(object sender, EventArgs e)
        {
            updateOptionalControls();
        }

        private void checkBackglassEnabled_CheckedChanged(object sender, EventArgs e)
        {
            updateOptionalControls();
        }
    }
}
